package net.esj.basic.service.impl;

import java.io.Serializable;

import net.esj.basic.dao.querybuilder.QueryBuilder;
import net.esj.basic.service.DefaultService;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.transaction.annotation.Transactional;

//@Service("defaultService")
//@Transactional
public class DefaultServiceImpl extends ServiceImpl implements DefaultService,InitializingBean {

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly=true)
	public <T> T getFull(Serializable id,Class<T> clazz , String... fetchs) {
		QueryBuilder qb = queryBuilderDao.getQueryBuilder(clazz);
		qb.eq("id", id);
		for(String fetch:fetchs){
			qb.fetch(fetch);
		}
		return (T) queryFirst(qb);
	}

	@Override
	@Transactional(readOnly=true)
	public <T,E> E getFull(Serializable id, Class<T> clazz, Class<E> targetClass,
			String... fetchs) {
		Object o = getFull(id, clazz, fetchs);
		if(o!=null){
			return (E) autoTransVo(o, targetClass);
		}
		return null;
	}

	/*@Override
	public int queryCountByMap(Map<String, Object> query, Class<?> tclass){
		return baseDao.queryCountByMap(query, tclass);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List queryListByMap(Map<String, Object> query, Class<?> tclass) {
		return baseDao.queryListByMap(query, tclass);
	}

	@Override
	public <T> Pagination<T> queryPageByMap(Pagination<T> page, Class<T> tclass) {
		return baseDao.queryPageByMap(page, tclass);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List queryTopByMap(Map<String, Object> query,
			Class<?> tclass, int count) {
		return baseDao.queryTopByMap(query, tclass, count);
	}*/

}
